
function sq_AddFunctionName(appendage)
{
	appendage.sq_AddFunctionName("proc", "proc_appendage_CatharsisChainLineAppendage")
	appendage.sq_AddFunctionName("onStart", "onStart_appendage_CatharsisChainLineAppendage")
	appendage.sq_AddFunctionName("onEnd", "onEnd_appendage_CatharsisChainLineAppendage")
}

function sq_AddEffect(appendage)
{
}

function onEnd_appendage_CatharsisChainLineAppendage(appendage)
{

	if(!appendage) {
		return;		
	}

	local vectorFlag = appendage.getVar("SizeVectorFlag").get_vector(0);

	for (local i = 0;i < vectorFlag;i++)
	{
		local line = appendage.getVar("lineObject" + i).get_obj_vector(0);
		if (line)
			line.setValid(false);
	}
}




function proc_appendage_CatharsisChainLineAppendage(appendage)
{
	if(!appendage) {
		return;		
	}

	local parentObj = appendage.getParent();
	
	if(!parentObj) 
	{
		appendage.setValid(false);
		return;
	}else
	{

		parentObj = sq_GetCNRDObjectToSQRCharacter(parentObj);
		local vectorFlag = appendage.getVar("SizeVectorFlag").get_vector(0);


		for (local i = 0;i < vectorFlag;i++)
		{
			local lineTarget = appendage.getVar("lineTarget_" + i).get_obj_vector(0);
			if (lineTarget)
			{
				
				local lenX = appendage.getVar("lineVar" + i).get_vector(0);
				local lenY = appendage.getVar("lineVar" + i).get_vector(1);
				local lineID = appendage.getVar("lineVar" + i).get_vector(2);
				local layer = appendage.getVar("lineVar" + i).get_vector(3);
				local flag = appendage.getVar("lineVar" + i).get_vector(4);

				if (appendage.getVar("lineObject" + i).get_obj_vector_size() <= 0)
				{
					if (flag == 0)
					{
						appendage.getVar("lineVar" + i).set_vector(4,1);


						local line = sq_AddDrawOnlyAniFromParent(parentObj,  
						"character/swordman/effect/animation/atcatharsis/wire_loop.ani",0,-1,0);

						appendage.getVar("lineObject" + i).push_obj_vector(line);

						sq_ChangeDrawLayer(line, ENUM_DRAWLAYER_COVER);
					}else
					{

						appendage.setValid(false);
						return;

					}

				}else
				{

					local offsetZ = 60;
					local offsetX = -16;
					local state = parentObj.getSkillSubState();

					local pAni = parentObj.sq_GetCurrentAni();
					local frmIndex = parentObj.sq_GetCurrentFrameIndex(pAni);
					if (state == 2 && frmIndex == 3)
					{
						local offsetZ = 52;
						local offsetX = -14;
					}

					if (state == 2 && frmIndex == 4)
					{
						local offsetZ = 79;
						local offsetX = 16;
					}

					if (state == 2 && frmIndex == 5)
					{
						local offsetZ = 79;
						local offsetX = 16;
					}

					if (state == 3)
					{
						local offsetZ = 21;
						local offsetX = -4;
					}

					local charX = sq_GetDistancePos(parentObj.getXPos(), parentObj.getDirection(), offsetX);
					//parentObj.getXPos();
					local charY = parentObj.getYPos() + 1;
					local charZ = parentObj.getZPos() + offsetZ; 

					local mobX = lineTarget.getXPos();
					local mobY = lineTarget.getYPos() + 1;
					local mobZ = lineTarget.getZPos() + lineTarget.getObjectHeight()/2;

					local line = appendage.getVar("lineObject" + i).get_obj_vector(0);
					if (parentObj.getYPos() > lineTarget.getYPos() )
						line.setCurrentPos(charX,charY,charZ );
					else
						line.setCurrentPos(charX,charY,charZ );

					local pAni = sq_GetCurrentAnimation(line);
					
					//initAngle 0.0 ~ 360.0
					local angle = getRorateAngleByCurrentPosEX(parentObj,
					charX,charY,charZ
					,mobX,mobY,mobZ ,0.0 );

					sq_SetfRotateAngle(pAni, angle);

					local distance = sq_GetDistance(charX, 
												charY - charZ,
												mobX ,
												mobY - mobZ, true);

					local len = 578.0;

					pAni.setImageRate(distance.tofloat() / len , distance.tofloat() / len *1.29 );

					if (mobX <= charX )
						line.setCurrentDirection(ENUM_DIRECTION_LEFT );
					else
						line.setCurrentDirection(ENUM_DIRECTION_RIGHT );

		
				}

			}else{
				
				local line = appendage.getVar("lineObject" + i).get_obj_vector(0);
				if (line)
					line.setValid(false);
			}

		}

	}
}


function onStart_appendage_CatharsisChainLineAppendage(appendage)
{
	if(!appendage) {
		return;
	}
	
	local parentObj = appendage.getParent();

	if(!parentObj) 
	{
		appendage.setValid(false);
		return;
	}

	appendage.getVar("SizeVectorFlag").clear_vector();
	appendage.getVar("SizeVectorFlag").push_vector(0);


}

